﻿@{
    ViewData["Title"] = "DifferenceAddIndex";
    Layout = null;
}


<link href="~/libs/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />


    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">盘点人</label>
            <div class="layui-input-block">
                <input type="text" id="stocker" name="stocker" lay-verify="required" placeholder="请输入盘点人" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">盘点日期</label>
            <div class="layui-input-block">
                <input type="date" id="stockDate" name="stockDate" lay-verify="required" placeholder="请输入盘点日期" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">储位</label>
            <div class="layui-input-block">
                <input type="text" placeholder="" name="storage" id="storage" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">托盘</label>
            <div class="layui-input-block">
                <input type="text" name="tray" id="tray" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">商品编码</label>
            <div class="layui-input-block">
                <input type="text" id="commodityCode" name="commodityCode" lay-verify="required" placeholder="请输入商品编码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-block">
                <input type="text" id="commodityName" name="commodityName" lay-verify="required" placeholder="请输入商品名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">账目数量</label>
            <div class="layui-input-block">
                <input type="number" id="accounts" name="accounts" lay-verify="required|number" placeholder="请输入账目数量" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">盘点数量</label>
            <div class="layui-input-block">
                <input type="number" id="stockNum" name="stockNum" lay-verify="required|number" placeholder="请输入盘点数量" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">生产日期</label>
            <div class="layui-input-block">
                <input type="date" id="protructDate" name="protructDate" lay-verify="required" placeholder="请输入生产日期" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">货主</label>
            <div class="layui-input-block">
                <input type="text" id="owner" name="owner" lay-verify="required" placeholder="请输入货主" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">货主编码</label>
            <div class="layui-input-block">
                <input type="text" id="ownerCode" name="ownerCode" lay-verify="required" placeholder="请输入货主编码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">单据状态</label>
            <div class="layui-input-block">
                <input type="radio" name="stockStatus" value="true" title="已完成" checked>
                <input type="radio" name="stockStatus" value="false" title="未完成">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                <button type="reset" class="layui-btn layui-btn-primary" onclick="closeWorkstation()">返回</button>
            </div>
        </div>
    </form>

    <script src="~/libs/layui-v2.5.6/layui/layui.js"></script>
    <script src="~/libs/jquery/jquery.js"></script>
    <script>
        layui.use(['form', 'laydate', 'layer'], function(){
          var form = layui.form;
          var layer = layui.layer;
          var laydate = layui.laydate;

          // 初始化日期选择器
          laydate.render({elem: '#stockDate'});
          laydate.render({elem: '#protructDate'});

          // 提交事件
          form.on('submit(demo1)', function(data){
            var field = data.field; // 获取表单字段值

            // 将 stockStatus 转换为布尔值
            field.stockStatus = Boolean(field.stockStatus);
            field.unit=1;
            field.stockDate=String(field.stockDate)
            console.log(field);

            $.ajax({
                url:'/Difference/AddDifference',
                type:'post',
                data:field,
                dataType:'json',
                success:function(res){
                    if(res.code == 1){
                        layer.alert('添加成功！', function(index){
                            closeWorkstation();
                            layer.close(index);
                        });
                    } else if(res.code == -100) {
                         layer.alert('已经有此单位名称！');
                    }
                },
                error: function() {
                    layer.alert('请求失败，请稍后再试！');
                }
            });

            return false; // 阻止默认 form 跳转
          });
        });

        // 关闭弹框
        function closeWorkstation() {
            var index = parent.layer.getFrameIndex(window.name); // 先得到当前的索引
            parent.layer.close(index); // 再执行关闭
        }
    </script>











